﻿using AutoMapper;
using B.S.Data.MES.API.Applications.BaseData.Command.CheJianCommand;
using B.S.Domain.BasicData.Factory_modeling.shop_management;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;

namespace B.S.Data.MES.API.Applications.BaseData.CommandHandlers.ChejianCommandHandlers
{
    public class UpdateCheJianCommandHandlers : IRequestHandler<UpdateCheJianCommand, APIRequst<int>>
    {
        private readonly IBaseRepository<shop_management> shopRepository;
        private readonly IMapper mapper;

        public UpdateCheJianCommandHandlers(IBaseRepository<shop_management> shopRepository,IMapper mapper)
        {
            this.shopRepository = shopRepository;
            this.mapper = mapper;
        }

        public async Task<APIRequst<int>> Handle(UpdateCheJianCommand request, CancellationToken cancellationToken)
        {
            shop_management shop = mapper.Map<shop_management>(request);
            shop.UpdateTime = DateTime.Now;
            shop.CreateTime=DateTime.Now;
            await shopRepository.Update(shop);
            return new APIRequst<int>
            {
                Msg = RequstCode.成功.ToString(),
                Code = RequstCode.成功
            };
        }
    }
}
